<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'selectuser.jsp' starting page</title>

		<script type="text/javascript"
			src="<%=path%>/commonjs/jquery-1.7.1.js">
</script>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<style type="text/css">
td {border：1px solid black;
	
}
</style>

	</head>

	<body>
		<table style="border: 1px solid;">
			<thead>
				个人信息如下：
				<tr>
					<td>
						id
					</td>
					<td>
						用户名
					</td>
					<td>
						密码
					</td>
					<td>
						电话号码
					</td>
					<td>
						权限
					</td>
				</tr>
			</thead>
			<tbody id="userinfo" style="border: 1px solid;">
			</tbody>
		</table>
		<div id="div_nodisplay" style="border: 1px solid red;width: 408px;display: none;margin-top: 5px;">
			<div style="background-color: #EEEEEE;">修改个人信息</div>
			<table>
				<tbody>
					<tr>
						<td>联系电话：</td>
						<td><input type="text" id="telephone"/></td>
					</tr>
					<tr>
						<td>原始密码：</td>
						<td><input type="password" id="password1"/></td>
					</tr>
					<tr>
						<td>新密码：</td>
						<td><input type="password" id="password2"/></td>
					</tr>
					<tr>
						<td>再次输入新密码：</td>
						<td><input type="password" id="password3"/></td>
					</tr>
					<tr>
						
						<td colspan="2">
							<input type="hidden" id="userId"/>
							<input type="button" value="提交" onclick="submitChange()"/>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<script type="text/javascript">
				$.post('<%=path%>/json/acquireSelfBasicInfo.action', {}, function(data) {
					var result = '<tr><td>' + data.user.id + "&nbsp;&nbsp;&nbsp;</td><td>"
							+ data.user.username + "&nbsp;&nbsp;&nbsp;</td><td>"
							+ data.user.password + "&nbsp;&nbsp;&nbsp;</td><td>"
							+ data.user.telephone + "&nbsp;&nbsp;&nbsp;</td><td>"
							+ data.user.login + "&nbsp;&nbsp;&nbsp;</td><td>";
					result = result + '';
					result = result + '<input type="button"  value="修改" onclick="updateUser('
							+ data.user.id + ');"/>&nbsp;&nbsp;';
					result = result + '</td></tr>';
					$(result).appendTo("#userinfo");
				
				}, 'json');
				
				function deleteuser(userid) {
					window.location.href = "deleteuser.action?userid=" + userid;
				}
				function updateUser(userid){
					$("#div_nodisplay").show();
					$("#userId").val(userid);
				}
				function submitChange(){
					var userId=$("#userId").val();
					var password1=$("#password1").val();
					
					
					var password2=$("#password2").val();
					var password3=$("#password3").val();
					var telephone=$("#telephone").val();
					if(password2!=null&&password3!=null&&password3!=password2)
					{alert("两次密码输入不一致！请重新输入！");return;}
					$.post('<%=path%>/json/modifyPersonalInfo.action',
					{userId:userId,password:password1,password1:password2,telephone:telephone}, 
					function(data) {
						alert(data.result);
					}, 'json');
					$("#div_nodisplay").hide();
				}
		</script>
	</body>
</html>
